package com.hopu.bean.era;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@ToString
public class Top3Bean implements Serializable , Comparable<Top3Bean> {

    private String era;
    private String type;
    private String cid;//类名ID
    private String cname;

    private int viewCount;//某个年代，某个类目的总浏览量
    private int cartCount;//加入购物车
    private int parchaseCount;//总销售量
    private int totalCount;

    public Top3Bean(String era, String type, String cid, String cname) {
        this.era = era;
        this.type = type;
        this.cid = cid;
        this.cname = cname;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        Top3Bean top3Bean = (Top3Bean) o;
        return Objects.equals(era, top3Bean.era) &&
                Objects.equals(cid, top3Bean.cid);
    }

    @Override
    public int hashCode() {
        return Objects.hash(era, cid);
    }

    @Override
    public int compareTo(Top3Bean o) {
        //先根据购买量比较
        //如果购买量相等，再根据加入购入车量进行比较
        if (this.getParchaseCount() == o.getParchaseCount()) {
            if (this.getCartCount() == o.getCartCount()) {
                return o.getViewCount() - this.getViewCount();
            } else {
                return o.getCartCount() - this.getCartCount();
            }
        } else {
            return o.getParchaseCount() - this.getParchaseCount();
        }
    }
}
